package com.haozi.ehub.core.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.haozi.ehub.core.mapper.AdminInfoMapper;
import com.haozi.ehub.core.service.AdminInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haozi.ehub.entity.code.DataCode;
import com.haozi.ehub.entity.entities.AdminInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author terry
 * @since 2020-06-15
 */
@Service
@Slf4j
@DS(value = DataCode.SLAVE_1)
public class AdminInfoServiceImpl extends ServiceImpl<AdminInfoMapper, AdminInfo> implements AdminInfoService {

    @Override
    @DS(DataCode.MASTER)
    @Transactional(rollbackFor = {Exception.class})
    public List<AdminInfo> insert(AdminInfo adminInfo) {
        super.save(adminInfo);
        System.out.println(adminInfo.toString());
        return super.list();
    }

    @Override
    public AdminInfo selectAdminByName(String adminName) {
        try {
            return baseMapper.selectAdminByName(adminName);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
            return new AdminInfo();
        }
    }
}
